#include "process.h"


const char* ROTATE = "/-|\\";
void process_v1()
{
    int rate = 0;
    char str[LENGTH] = {'\0'};
    memset(str,'\0',sizeof str);

    while(rate <= RATE_MAX)
    {
        printf("[%-100s][%2d%%][%c]\r", str, rate*100/RATE_MAX, ROTATE[rate%4]);
        fflush(stdout);
        usleep(TIME);
        str[rate++] = STYLE;
    }
    printf("\n");
}
void process_v2(double rate)
{
    static char str[LENGTH] = {'\0'};
    
    printf("[%-100s][%.1f%%][%c]\r", str, rate, ROTATE[(int)rate%4]);
    fflush(stdout);
    if(rate < RATE_MAX)
        str[(int)rate] = STYLE;
}
void download(callback cb)
{
    double cur = 0;
    while(cur < TOTAL)
    {
        cur += (int)DOWNLOADSIZE;//这里都不需要显示转换，因为有cur
        usleep(TIME);//模拟下载需要的时间
        double rate = cur*100/TOTAL;
        cb(rate);
    }
    cb(RATE_MAX);//传进去的100比率
    printf("\n");
}
